﻿@{
    ViewBag.Title = "Home";
}
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<style type="text/css">
    p {
        padding-left:50px;
    }
</style>
<div style="margin:50px;"></div>
<div class="panel panel-default">
    @if (Model == null)
    {
        <form method="post" enctype="multipart/form-data" action="/Home/index" class="panel-body">
            <table class="table table-striped" style="width:80%;margin-left:10%;">
                <tbody>
                    <tr>
                        <td style="text-align:right"><label>输入翻译文件/文件夹路径（服务器端）:</label></td>
                        <td><input type="text" name="path" class="form-control" value="" /></td>
                    </tr>

                    <tr>
                        <td style="text-align:right"><label>UploadEXCEL:</label></td>
                        <td><input type="file" name="file" style="display: block;width: 100%;height: 34px;padding: 3px 5px;font-size: 14px;line-height: 1.428571429;color: #555555;vertical-align: middle;background-color: #ffffff;border: 1px solid #cccccc;border-radius: 4px;" /></td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align:right"><input type="submit" value="开始" class="btn btn-primary" style="width:100px;" /></td>
                    </tr>
                </tbody>
            </table>
        </form>
    }
    else if (Model)
    {
        <div class="alert alert-info" role="alert" style="margin:20px;">
            <h4 style="color:blue">翻译文件开始：</h4>
            <div id="message" style="color:#000"></div>
        </div>
        <script src="~/Scripts/jquery-1.10.2.min.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>
        <script>
            $(function () {
                window.time1 = setTimeout(function () { $("#message").append("<p>读取excel</p>"); one(); }, 1000);
                function one() {
                    window.clearTimeout(time1);
                    window.time2 = setTimeout(function () { $("#message").append("<p>读取excel完毕</p>"); two(); }, 1000);
                }

                function two() {
                    window.clearTimeout(time2);
                    $.ajax({
                        url: "@Url.Action("ReturnExcelCount","Home")",
                        dataType: 'text',
                        success: function (data) {
                            window.time3 = setTimeout(function () { $("#message").append("<p>翻译清单条数为：" + data + "</p>"); san() }, 1000);
                        }
                    });
                }

                function san() {
                    window.clearTimeout(time3);
                    window.time4 = setTimeout(function () { $("#message").append("<p>开始遍历文件夹</p>"); si(); }, 1000);
                }

                function si() {
                    window.clearTimeout(time4);
                    window.time6 = setTimeout(function () { $("#message").append("<p>找到(*.cshtml)文件条数：<span id='contee'>0</span></p>"); lll(); }, 1000);
                }

                function lll() {
                    window.clearTimeout(time6);
                    window.time5 = window.setInterval(function () {
                        $.ajax({
                            url: "@Url.Action("ReturnFileModels", "Home")",
                            dataType: 'text',
                            success: function (data) {
                                $("#contee").text(data);
                            }, error: function () { window.clearInterval(time5); }
                        });
                    }, 50);

                    $.ajax({
                        url: "@Url.Action("TraversalFile", "Home")",
                        dataType: 'json',
                        success: function (data) {
                            if (data.Result) {
                                window.time7 = setTimeout(function () { $("#message").append("<p>文件读取完毕</p>"); qwwqq(); }, 1000);
                            }
                            else {
                                window.clearInterval(time5);
                                $("#message").append("<p style='color:red'>未找到相关文件，执行结束！</p>");
                            }
                        }, error: function () { window.clearInterval(time5); }
                    });
                }

                function qwwqq() {
                    window.clearTimeout(time7);
                    window.clearInterval(time5);
                    window.time8 = setTimeout(function () { $("#message").append("<p>开始遍历文件,翻译字段</p>"); qqq(); }, 1000);
                }

                function qqq() {
                    window.clearTimeout(time8);
                    window.time9 = setTimeout(function () { $("#message").append("<p>已完成翻译文件条数：<span id='sasasas'>0</span></p>"); asdasd(); }, 1000);
                }

                function asdasd() {
                    window.clearTimeout(time9);
                    window.time10 = window.setInterval(function () {
                        $.ajax({
                            url: "@Url.Action("ReturnSucessCount", "Home")",
                            dataType: 'text',
                            success: function (data) {
                                $("#sasasas").text(data);
                            },
                            error: function () { window.clearInterval(time10); }
                        });
                    }, 300);

                    $.ajax({
                        url: "@Url.Action("loopFile", "Home")",
                        dataType: 'json',
                        success: function (data) {
                            if (data.Result) {
                                window.time11 = setTimeout(function () { $("#message").append("<p>写人\"_en\"文件完毕</p>"); sadasdasd(); }, 1000);
                            }
                            else {
                                $("#message").append("<p style='color:red'>未找到相关文件，执行结束！</p>");
                            }
                        },
                        error: function () { window.clearInterval(time10); }
                    });
                }

                function sadasdasd() {
                    window.clearTimeout(time11);
                    window.clearInterval(time10);
                    window.time12 = setTimeout(function () { $("#message").append("<p>执行结束！</p>"); }, 1000);
                }
            })
        </script>
    }
    else
    {
        <div class="alert alert-danger" role="alert" style="margin-top:20px;">执行失败，请检查excel是否正确</div>
    }
</div>
